#include <iostream>
#include <memory>
#include "epoll_server_v4.hpp"
#include "task.hpp"
#include "protocol.hpp"

void usage(const std::string& proc)
{
    std::cout << "Uasge:\n\t" << proc << " port\n" << std::endl;
}

std::string echo_service(const std::string& req)
{
    return "echo service >>> " + req;
}

proto::response calc_service(const proto::request req)
{
    task t(req._x, req._y, req._op);
    t();
    INFO("calc expression " + t.expression_str());
    
    return proto::response(t.get_res(), t.get_st());
}

int main(int argc, char* argv[])
{
    if (argc != 2)
    {
        usage(argv[0]);
        exit(1);
    }
    uint16_t port = std::stoi(argv[1]);

    std::unique_ptr<server::epoll_server> psvr(new server::epoll_server(port, calc_service, true));
    psvr->init();
    psvr->dispatcher();
    
    return 0;
}
